#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@create Time:2018-11-16

@author:Brook

定时调度器

"""
import os
import threading
import requests

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor
from extra_apps.django_apscheduler.jobstores import DjangoJobStore, register_events, register_job


_schd = None


def get_scheduler():
    global _schd
    if _schd is None:
        jobstores = {
            'default':DjangoJobStore(),
        }
        executors = {
            "default":ThreadPoolExecutor(20),
        }
        job_defaults = {
            "coalesce":False,
            "max_instances":5,
        }
        schd = BackgroundScheduler(jobstores=jobstores, executors=executors,job_defaults=job_defaults)
        schd.start()
        register_events(schd)
        _schd = schd
    return _schd


